package homework1.test06;

public class Rectangle {
    // 私有属性：长和宽
    private double length;
    private double width;

    public Rectangle(double length, double width) {
        this.length = length;
        this.width = width;
    }
    public Rectangle() {}

    // 长的getter和setter方法
    public double getLength() {
        return length;
    }

    public void setLength(double length) {
        this.length = length;
    }

    // 宽的getter和setter方法
    public double getWidth() {
        return width;
    }

    public void setWidth(double width) {
        this.width = width;
    }

    // 计算面积
    public double getArea() {
        return length * width;
    }

    // 计算周长
    public double getPerimeter() {
        return 2 * (length + width);
    }

    // 返回矩形对象的信息
    public String getInfo() {
        return String.format("长: %.1f, 宽: %.1f, 面积: %.1f, 周长: %.1f",
                length, width, getArea(), getPerimeter());
    }

    @Override
    public String toString() {
        return "Rectangle{" +
                "length=" + length +
                ", width=" + width +
                '}';
    }
}
